package com.se.back.service.impl;

import com.se.back.entity.Customer;
import com.se.back.entity.User;
import com.se.back.repository.IBusinessRepository;
import com.se.back.repository.ICustomerRepository;
import com.se.back.service.LoginService;
import com.se.back.entity.Business;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {

    private final IBusinessRepository businessRepository;
    private final ICustomerRepository customerRepository;


    public LoginServiceImpl(IBusinessRepository businessRepository, ICustomerRepository customerRepository) {
        this.businessRepository = businessRepository;
        this.customerRepository = customerRepository;
    }

    @Override
    public User userLogin(String id, String password) {
        Customer customer = customerRepository.findByCustomerIdAndPassword(id, password);
        if (customer!=null){
            customer.setUserType("customer");
            return customer;
        }

        Business business = businessRepository.findByBusinessIdAndPassword(id, password);
        if (business!=null){
            business.setUserType("business");
            return business;
        }
        return null;
    }
}
